package test;

import java.awt.Image;
import java.awt.image.PixelGrabber;
import java.nio.ByteBuffer;

import javax.swing.ImageIcon;


class GLImage{
    public ByteBuffer data;
    public int width, height;

    /** Create a GLImage from a regular Image object. */

    public GLImage(Image image) throws InterruptedException
	      {
      width = image.getWidth(null);
      height = image.getHeight(null);

      // Extract the image data and convert it to the proper format.

      PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, true);
      pg.grabPixels();
      int templatePixel[] = (int []) pg.getPixels();
      byte dataArray[] = new byte [templatePixel.length*4];
      int pos = 0;
      for (int row = 0; row < height; row++)
        for (int col = 0; col < width; col++)
	          {
          int argb = templatePixel[width*(height-row-1)+col];
          dataArray[pos++] = (byte) (argb>>16);
          dataArray[pos++] = (byte) (argb>>8);
          dataArray[pos++] = (byte) (argb);
          dataArray[pos++] = (byte) (argb>>24);
        }
      data = ByteBuffer.wrap(dataArray);
      
      for (int row = 0; row < height; row++)
          for (int col = 0; col < width; col++)
  	          {
        	  System.out.println(data.getInt());
  	          }
    }
    
    
    public static void main(String[] args){
    	Image img = (new ImageIcon("E:\\bn.jpg")).getImage();
    	try {
			GLImage itp = new GLImage(img);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    }
    
    
  }

